package com.zbw;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@PropertySource("classpath:application.yml")
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)	//指定API类型为swagger2
                .apiInfo(apiInfo())
                .groupName("第一组")
                .enable(true)//用于定义API文档的相关信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zbw.controller")) //指定controller层包名
                .paths(PathSelectors.any())				//应用于所有的controller
                .build();
    }
    @Bean
    public Docket createRestApi2() {
        return new Docket(DocumentationType.SWAGGER_2)	//指定API类型为swagger2
                .apiInfo(apiInfo())
                .groupName("第二组")
                .enable(true)//用于定义API文档的相关信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zbw.controller")) //指定controller层包名
                .paths(PathSelectors.any())				//应用于所有的controller
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()//
                .title("这是title~~~")				//API文档的标题
                .description("这是描述~~~~")	//关于这个文档作用的描述
                .version("这是版本号~~~")			//设置当前API文档的版本号
                .build();
    }
}
